<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.global.js"></script>
    <link rel="stylesheet" href="css/3-3-01-list.css">
</head>

<body>
    <div id="app">
        <div id="contain">
            <h2>提醒事项</h2>
            <div class="item">
                <span>内容</span>
                <input type="text" v-model="newContent" id="newContent">
                <button id="pull" @click="addItem">添加</button>
            </div>
            <transition-group name="list" tag="ul" id="content">
                <li v-for="(item, index) in list" :key="item">
                    <span>{{ index + 1 }}</span>
                    <span>{{ item }}</span>
                    <div id="btn-right">
                        <button v-if="index < list.length - 1" @click="moveDown(index)">下滑</button>
                        <button v-else disabled>下滑</button>
                        <button v-if="index > 0" @click="moveUp(index)">上移</button>
                        <button v-else disabled>上移</button>
                        <button @click="removeItem(index)">删除</button>
                    </div>
                </li>
            </transition-group>
        </div>
    </div>
    <script>
        Vue.createApp({
  data() {
    return {
      newContent: "",
      list: [
        "吃饭", "睡觉", "打豆豆"
      ]
    }
  },
  methods: {
    addItem() {
      if (this.newContent.length <= 0) {
        alert('请输入内容');
      } else {
        this.list.push(this.newContent);
        this.newContent = "";
      }
    },
    removeItem(index) {
      this.list.splice(index, 1);
    },
    moveDown(index) {
      if (index < this.list.length - 1) {
        [this.list[index], this.list[index + 1]] = [this.list[index + 1], this.list[index]];
      }
    },
    moveUp(index) {
      if (index > 0) {
        [this.list[index], this.list[index - 1]] = [this.list[index - 1], this.list[index]];
      }
    }
  }
}).mount('#app');
    </script>
</body>

</html>